
class Observable;

class Observer {
public:
	virtual void onUpdate(Observable* sender, int msg, const any& arg) = 0;
};

class Observable {

public:
	void AddListener(Observer* t) {
		listeners.push_back(t);
	}
	void RemoveListener(Observer* t) {
		vector<Observer*>::iterator it = std::find(listeners.begin(),
				listeners.end(), t);
		if (it != listeners.end()) {
			listeners.erase(it);
		}
	}

	void FireEvent(int msg, const any& arg) {
		vector<Observer*> vec = listeners;//copy
		vector<Observer*>::iterator it = vec.begin();
		while (it != vec.end()) {
			Observer* obs = *it;
			obs->onUpdate(this, msg, arg);
			++it;
		}
	}
private:
	vector<Observer*> listeners;
};
